//
//  BuildingSearchNav.swift
//  TRHouse
//
//  Created by zhu xietong on 2018/5/16.
//  Copyright © 2018年 tianrun. All rights reserved.
//

import UIKit
import Eelay

open class EeSearchNav: JoView {
    public weak var controller:UIViewController?{
        didSet{
            searchBar.mo_controller = controller
            searchBar.owner = controller
            let num = controller?.navigationController?.viewControllers.count ?? 0
            if num > 1{
                self.haveNavBackBt = true
            }
            else{
                haveNavBackBt = false
            }
            
        }
    }
    public let leftBt = UIButton()
    public let titleL = UILabel()
    public let rightBt = UIButton()
    
    public let searchBar = SearchBar()
    
    
    
    public var navTransparent:NavTransparent = .no{
        didSet{
//            switch navTransparent {
//            case .yes:
//                _ = titleL.ui.cl_fff
//                leftBt.setImage(#imageLiteral(resourceName: "me_6sz").rt_tintedImage(with: .white), for: .normal)
//                rightBt.setImage(#imageLiteral(resourceName: "iwe_youxiang").rt_tintedImage(with: .white), for: .normal)
//            default:
//                _ = titleL.ui.cl_222
//                leftBt.setImage(#imageLiteral(resourceName: "me_6sz").rt_tintedImage(with:  UIColor(shex:"#333")), for: .normal)
//                rightBt.setImage(#imageLiteral(resourceName: "iwe_youxiang").rt_tintedImage(with:  UIColor(shex:"#333")), for: .normal)
//            }
        }
    }
    
    override open func addLayoutRules() {
        self.frame = [0,0,(Swidth-30),44]
        eelay = [
            [searchBar,[ee.Y,0.+1000],[ee.T.B]]
        ]
        haveNavBackBt = false
        
//        var offSet:(left:CGFloat,right:CGFloat) = (0,0)        
//        if haveNavBackBt{
//            offSet = (-20,-10)
//        }
        
        
        self.haveNavBackBt = true
    }
    public var cons = [NSLayoutConstraint]()
    
    public var haveNavBackBt = true{
        didSet{
            var offSet:(left:CGFloat,right:CGFloat) = (0,0)
            self.removeConstraints(cons)

            if haveNavBackBt{
                offSet = (0,-10)
            }

            let left = NSLayoutConstraint(item: searchBar, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1, constant: offSet.left)
            let right = NSLayoutConstraint(item: searchBar, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1, constant: offSet.right)
            self.cons = [left,right]
            self.addConstraints(cons)
        }
    }
    override open func layoutSubviews() {
        super.layoutSubviews()
    }
    
    @objc open func showMenu() {
    }
    
    @objc open func gotoSearch() {
//        let ctr = BuildingListCtr()
//        controller?.navigationController?.pushViewController(ctr, animated: true)
     
    }
    
    
    override open var intrinsicContentSize: CGSize{
        get{
            return frame.size
        }
    }
    
}
